// pages/user-hyzx-ckxx-xiugai/user-hyzx-ckxx-xiugai.js
var util = require('../../utils/network.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
      name:'',
      idcard:'',
      tel:'',
      id:'',
      idnum:'',
      cardtype:'',
      bShow:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this
    that.setData({
        name: options.name,
        idcard: options.idnum,
        tel: options.phonenum,
        id: options.id,
        cardtype: options.cardtype
    })
  },
  formSubmit:function(e){
        var token = util.token
        var that=this
        var userId=wx.getStorageSync('userId')
        var idnum = e.detail.value.idcard
        var tel = e.detail.value.tel
        var name = e.detail.value.name
        if (idnum != '' & tel!='' & name!=''){
            wx.request({
                url: util.main + '/passenger/updatePi',
                data: {
                    "passengerInfo.userid": userId,
                    "passengerInfo.id": that.data.id,
                    "passengerInfo.name": name,
                    "passengerInfo.cardtype": that.data.cardtype,
                    "passengerInfo.idnum": idnum,
                    "passengerInfo.phonenum": tel,
                    "deviceid": wx.getStorageSync('openId'),
                    "token": token
                },
                header: {
                    "content-type": "application/x-www-form-urlencoded",
                    "accept": "application/json,",
                },
                method: "POST",
                dataType: "json",
                success: function (res) {
                    wx.redirectTo({
                        url: '../user-hyzx-ckxx/user-hyzx-ckxx',
                    })
                }
            })
        }else{
            that.setData({
                bShow:true
            })
            setTimeout(function(){
                that.setData({
                    bShow: false
                })
            },3000)
        }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})